<%--
 *  File:   uploadcolumnconfiger.jsp
 *  Desc:	
 *
 *  Date	  :	 2013-05-31     
 *  Author	:  jeanhuang
 *
 *  Copyright (C) 2000 - 2005 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%
	//init param
  String strModuleName = "DMS";
  String privilegeCode = "IMG0303";
  String contextPath = request.getContextPath();
  
  String struploadconfigid=request.getParameter("uploadconfigid")+"";
  if(session.getAttribute("uploadconfigid")!=null){
		struploadconfigid=session.getAttribute("uploadconfigid")+"";
	}
  
boolean onlyflag = false;
%>
<%@ include file="/inc/CommonHeader.inc" %>

<html>
<head>
<title>uploadcolumnconfiger</title>
<PageFlow:CheckPageFlow pageName="p_uploadcoloumnconfig"/>
<%@ include file="/inc/AlertError.inc" %>
<%
  Vector configcolumndatas = (Vector)pageContext.getAttribute("configcolumndatas");
  if(configcolumndatas == null) configcolumndatas = new Vector();
  HashMap pkinfo =(HashMap)pageContext.getAttribute("pkinfo");
  String checkpk="no";
  if(pkinfo!=null&&pkinfo.size()>0){
	  checkpk="yes";
  }
%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/Calendar.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<iframe name="reloadHandler" style="display:none"></iframe>
<script language="JavaScript">

function clickComboCode(id)
{
  document.cform.id.value = id;
}

function page_add()
{
	var onlyflag = document.cform.onlyflag.value;
    //if(!checkALLElems(document.getElementById("newdetail"))) return;
    var sortno=document.cform.addsortno.value;
    var columndesc=document.cform.addcolumndesc.value;
    var tablename=document.cform.addtablename.value;
    var columnname=document.cform.addcolumnname.value;
    var columntype=document.cform.addcolumntype.value;
    var type=document.cform.addtype.value;
    
    if(sortno==null||sortno==""||sortno==-1){
    	alert("<%= message.getMessageDesc("VALUE_NOT_NULL", label.getLabelName("L_SortNo",false)) %>");
        return;
    }
    if(columndesc==null||columndesc==""||columndesc==-1){
    	alert("<%= message.getMessageDesc("VALUE_NOT_NULL", label.getLabelName("L_ElementName",false)) %>");
        return;
    }
    if(tablename==null||tablename==""||tablename==-1){
    	alert("<%= message.getMessageDesc("VALUE_NOT_NULL", label.getLabelName("L_VtableName",false)) %>");
        return;
    }
    if(columnname==null||columnname==""||columnname==-1){
    	alert("<%= message.getMessageDesc("VALUE_NOT_NULL", label.getLabelName("L_ElementName",false)) %>");
        return;
    }
    if(columntype==null||columntype==""||columntype==-1){
    	alert("<%= message.getMessageDesc("VALUE_NOT_NULL", label.getLabelName("L_SYSColumnType",false)) %>");
        return;
    }
    if(type==null||type==""||type==-1){
    	alert("<%= message.getMessageDesc("VALUE_NOT_NULL", label.getLabelName("L_OnlyOneSign",false)) %>");
        return;
    }
    
    if(!isInteger(cform.addsortno.value)||cform.addsortno.value<=0){
    	alert("<%= message.getMessageDesc("SEQUENCE_MUST_POSITION", label.getLabelName("L_SortNo",false)) %>");
    	cform.addsortno.focus();
    	return;
    }

    if(!onlyflag){
    	if(type != 1){
    		alert("<%= message.getMessageDesc("NEED_ONLY_FLAG") %>");
    		return;
        }
       }
    //changedField();
    cform.addcolumntype.disabled="";
    cform.actionname.value = "add";
    cform.target = "_self";
    cform.submit();
}
function page_delete()
{
    if(!confirm("<%= message.getMessageDesc("ARE_YOU_SURE_DEL") %>")) return;
    cform.actionname.value = "delete";
    cform.target = "_self";
    isRunning = true;
    cform.submit();
}
function page_save()
{
	var onlyflag = document.cform.onlyflag.value;
    //if(!checkALLElems(document.getElementById("olddetail"))) return;
    if(!checkForm(cform)) return;
    emptyToNull(cform);
	if(onlyflag){
		alert("<%= message.getMessageDesc("NEED_ONLY_FLAG") %>");
		return;
	}
    
    cform.actionname.value = "save";
    cform.target = "_self";
    isRunning = true;
    cform.submit();
}

function page_back(){
	parent.location.href="uploadConfigSummary.jsp?<%=OvalTools.randomURL()%>";
}

function setReadonly(){
	var numrows = cform.numrows.value;
	for(var i=0 ; i < numrows; i++){
		eval("cform.sourcesequence"+i).disabled = "disabled";
	}
}


function changevalue(obj){
	if(obj.checked){
		document.cform.iskeycolumn.value='Y';
	}else{
		document.cform.iskeycolumn.value='N';
	}
}

function changesetvalue(idx){
	//alert(eval("document.cform.columnname"+id+".options.length=1"));
	//document.cform.columnname+id.options.length=1;
	//var a = eval("document.cform.columnname"+id).options.length;
	var tablename =  eval("document.cform.tablename"+idx);
	var columnname =  eval("document.cform.columnname"+idx);
	
	var textobj=tablename.options[tablename.selectedIndex].text;
	if(tablename.value!=""&&tablename.value!=null&&tablename.value!=-1){
		columnname.disabled = false;
		tablename.value=textobj;
		setkeyvalue(tablename.value,textobj,idx);
	}else{
		columnname.disabled = true;
		tablename.value="";
	}
}

function addchangesetvalue(){
	var textobj=document.cform.addtablename.options[document.cform.addtablename.selectedIndex].text;
	if(document.cform.addtablename.value!=""&&document.cform.addtablename.value!=null&&document.cform.addtablename.value!=-1){
		document.cform.addcolumnname.disabled = false;
		document.cform.addtablename.value=textobj;
		addsetkeyvalue(document.cform.addtablename.value,textobj);
	}else{
		document.cform.addcolumnname.disabled = true;
		document.cform.addtablename.value="";
	}
}

function setkeyvalue(tableid,tablename,idx){
	var  datahandler = new  DataHandler() ;
	  //datahandler.add_params("tableid" ,tableid,"Integer");
	   datahandler.add_params("tablename" ,tablename,"String");
	  //datahandler.add_params("ispk" ,ispk,"String");
	  datahandler.add_params("languagecode" ,"<%=strLanguageCode %>","String");
	  datahandler.add_job("j_gettableinfo");
	   
	  datahandler.getResultFromVector("columndatas","columnname" ,"columnname","document.cform.columnname"+idx);
	  datahandler.getResultFromVector("columndatas","columntype" ,"columntype","document.cform.columntype"+idx)
	  datahandler.runDataHandler();
}

function addsetkeyvalue(tableid,tablename){
	var  datahandler = new  DataHandler() ;
	  //datahandler.add_params("tableid" ,tableid,"Integer");
	   datahandler.add_params("tablename" ,tablename,"String");
	  //datahandler.add_params("ispk" ,ispk,"String");
	  datahandler.add_params("languagecode" ,"<%=strLanguageCode %>","String");
	  datahandler.add_job("j_gettableinfo");
	   
	  datahandler.getResultFromVector("columndatas","columnname" ,"columnname","document.cform.addcolumnname");
	  datahandler.getResultFromVector("columndatas","columntype" ,"columntype","document.cform.addcolumntype")
	  datahandler.runDataHandler();
}

function changedField(idx)
{
	var a = "cform.columntype"+idx+".options[cform.columnname"+idx+".selectedIndex]";
	eval(a).selected=true;
}
function addchangedField()
{
	var a = "cform.addcolumntype.options[cform.addcolumnname.selectedIndex]";
	eval(a).selected=true;
}
</script>
<body style="overflow: auto;">
<form name="cform" method="post" action="<%=contextPath%>/Dispatcher" >
  <input type="hidden" name="pagename" value="p_uploadcoloumnconfig">
  <input type="hidden" name="actionname">
  <custom:hidden property="uploadconfigid" value="<%=struploadconfigid %>" />
   <input type=hidden name=nums value="<%=JspHelper.filterNull(configcolumndatas.size())%>">
  <input type="hidden" name="numrows" value="<%= configcolumndatas.size() %>">

<table border=0 cellpadding=0 cellspacing=0 width="100%">
  <tr>
    <td valign=top>
      <table border=0 cellpadding=1 cellspacing=0 width="100%">
        <tr>
          <td bgcolor=#000000 style="PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; PADDING-TOP: 0px">
            <table bgcolor=#000000 border=0 cellpadding=0 cellspacing=0 width="100%">
              <tr>
                <td  bgcolor=#ffffff style="PADDING-BOTTOM: 3px; PADDING-LEFT: 3px; PADDING-RIGHT: 3px; PADDING-TOP: 3px">
                    <table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%" cellpadding="1">

<%--    top function buttons    --%>
<% if(!isView){%>
                    <tr>
                        <td colspan="20" class="td_right">
                       
                          <a onclick="page_add();"><custom:button type="2" label="L_Add" imgsrc="add_btn.gif" border="0"/></a>
                       	  <a onclick="page_save();"><custom:button type="2" label="L_Save" imgsrc="add_btn.gif" border="0"/></a>
                          <%if(configcolumndatas.size()>0 ){%>
<!--                          <a onclick="page_save()"><custom:button type="2" label="L_Save" imgsrc="save_btn.gif" border="0"/></a>-->
                          <a onclick="page_delete();"><custom:button type="2" label="L_Delete" imgsrc="delete_btn.gif" border="0"/></a>
                          <%}%>
                        </td>
                      </tr>
<%}%>

<tr  class="deepblue-left"> 
	<td width="22" class="title_center">&nbsp;</td>
	<td width="10%" class="title_center"><%= label.getLabelName("L_SortNo") %><font color="red">*</font></td>
	<td width="20%" class="title_center"><%= label.getLabelName("L_ElementName") %><%= label.getLabelName("L_ReportDesc") %><font color="red">*</font></td>
	<td width="20%" class="title_center"><%= label.getLabelName("L_VtableName") %><font color="red">*</font></td>
	<td width="20%" class="title_center"><%= label.getLabelName("L_ElementName") %><font color="red">*</font></td>
	<td width="20%" class="title_center"><%= label.getLabelName("L_SYSColumnType") %><font color="red">*</font></td>
	<td  class="title_center"><%= label.getLabelName("L_OnlyOneSign") %><font color="red">*</font></td>
	
</tr>
<span id="olddetail" >
				 		  <%
				             int j = 0;
				             String strClassType = new String();
				             Integer nDefaultId = new Integer(-1);
				             boolean bHasChecked = false;
				          %>
                    <logic:iterate id="onerow" collection="<%= configcolumndatas %>" indexId="idx">
                        <%
				            HashMap hashdatas = (HashMap)pageContext.getAttribute("onerow");
				
				            String strIsDisabled = new String("");
				            String strIsChecked = new String("");
				
				            if(j%2 == 1){
				              strClassType = "td-listrom";
				            }else{
				              strClassType = "";
				            }
				           if(!bHasChecked)
				            {
				              strIsChecked = "Checked";
				              bHasChecked = true;
				              nDefaultId = (Integer)(hashdatas.get("uploadcolumnconfigid"));
				            }
				           if(hashdatas.get("type") != null && hashdatas.get("type").toString().equals("1")){
				        	   onlyflag = true;
				           }
				            j++;
         			 %>
         	
                      <tr>
                        <td width="30">
                        <input id="deletes<%=JspHelper.filterNull(j)%>" type="radio" name="checkdept"  value=<%=JspHelper.filterNull( hashdatas.get("uploadcolumnconfigid") )%> class="checkbox" <%=JspHelper.filterNull( strIsChecked)%> onClick="javascript:clickComboCode('<%=JspHelper.filterNull( hashdatas.get("uploadcolumnconfigid") )%>')">
                        </td>
                        <td><custom:text name="onerow" property="sortno" colIndex="<%=idx %>" command="notnull" label="L_SortNo"/><custom:hidden name="onerow" property="uploadcolumnconfigid" colIndex="<%=idx %>"/></td>
                        <td><custom:text name="onerow" property="columndesc" colIndex="<%=idx %>" command="notnull" label="L_ElementName"/></td>
                        <td>
                        	<%
                        	String tablemethod = "changesetvalue("+(j-1)+");";
                        	%>
                        	<custom:select optionsName="alltables" name="onerow" property="tablename" optionInnerTextKey="tablename" optionValueKey="tablevalue" defaultValue="---------" onchange="<%= tablemethod%>" colIndex="<%=idx %>" command="notnull" label="L_VtableName"/>
                        </td>
                        <td>
                        <%
                        	String colnumtemp = hashdatas.get("columnname")+""; 
                        	String namemethod = "changedField("+(j-1)+");";
                        %>
                        	<custom:select optionsName="columndatas" name="aaa" property="columnname" optionValueKey="columnname" value="<%=colnumtemp %>" optionInnerTextKey="columnname"  defaultValue="----------" onchange="<%= namemethod %>"  colIndex="<%=idx %>" command="notnull" label="L_ElementName"/>
                        </td>
                        <td>
                        	<custom:select name="onerow" property="columntype" optionsName="columndatas" optionValueKey="columnname" value="<%=colnumtemp %>" optionInnerTextKey="columntype"  disabled="true" defaultValue="----------" colIndex="<%=idx %>" command="notnull" label="L_SYSColumnType"/>
                        </td>
                        <td>
                        <%
                        	String valuenametemp = hashdatas.get("value")+""; 
                        %>
                        <custom:selectdic name="onerow" property="type" dictType="columnType"  value="<%=valuenametemp %>" defaultValue="-------------" colIndex="<%=idx %>" command="notnull" label="L_OnlyOneSign"/>
                        </td>
                       
                   </tr>
                      
                      </logic:iterate>
                    
</span>

 <input type="hidden" name="id" value="<%=JspHelper.filterNull( nDefaultId )%>">
 <input type="hidden" name="onlyflag" value="<%=JspHelper.filterNull( onlyflag )%>">
<% if(!isView){%>

<span id="newdetail" >
                      <tr >
                        <td>&nbsp;</td>
                        
                        <td>
                        <custom:text name="newdetail" property="addsortno"  />
<!--                        command="notnull" Label="L_SortNo" model="IMG" -->
                        </td>

                        <td>
                       <custom:text name="newdetail" property="addcolumndesc"/>
<!--                       command="notnull" Label="L_ElementName" model="IMG"-->
                       </td>

                        <td>
                       	<custom:select optionsName="alltables" name="newdetail" property="addtablename" optionInnerTextKey="tablename" optionValueKey="tablename" defaultValue="---------" onchange="addchangesetvalue()" />
<!--                       	 <custom:hidden name="newdetail" property="tablename" command="notnull" label="L_VtableName" module="IMG" />-->
                        </td>
                         <td><custom:select name="newdetail" property="addcolumnname" optionsName="columndatas" optionValueKey="columnname" optionInnerTextKey="columnname" defaultValue="---------" onchange="addchangedField();"/></td>
                         <td><custom:select name="newdetail" property="addcolumntype" optionsName="columndatas" optionValueKey="columntype" optionInnerTextKey="columntype"  disabled="true"  />
                         </td>
                         <td>
                          <custom:selectdic name="newdetail" property="addtype" dictType="columnType"  value="2"  />
<!--                         <custom:hidden name="newdetail" property="iskeycolumn" value="N" />-->
                         </td>
                      </tr>

</span>
<%}%>
                    </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      <table width="100%" cellspacing="0" cellpadding="0">
         <tr><td class="summary_top"></td></tr>
         <tr>
           <td class="td_center">
          
             <a onclick="page_back();"><custom:button type="1" label="L_Back" imgsrc="new.gif" border="0" style="width:60"/></a>
          
           </td>
         </tr>
      </table>
    </td>
  </tr>
</table>
</form>
</body>
<script>
	//setReadonly();
</script>
</html>